package p1;

public class T11 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person2 p=new Person2(new MyDate2(1998,3,5),"张老三");
        System.out.println(p);
        Person2 p2=(Person2) p.clone();
        System.out.println(p);
        System.out.println(p2);
        System.out.println(p.equals(p2));
        p2.getBirthday().setMonth(8);
        System.out.println(p2);
        System.out.println(p);
    }
}
class MyDate2 implements Cloneable{
    public static int thisYear;
    private int year;
    private int month;
    private int day;
    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }


    static {
        thisYear=2024;
    }
    public MyDate2(int month,int day){
        year=thisYear;
        this.month=month;
        this.day=day;
    }
    public MyDate2(int year,int month,int day){
        this.year=year;
        this.month=month;
        this.day=day;
    }

    @Override
    public String toString() {
        return String.format("[%d-%d-%d]",year,month,day);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return new MyDate2(year,month,day);
    }
}
class Person2 implements Cloneable{
    private MyDate2 birthday;
    private String name;

    public MyDate2 getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate2 birthday) {
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Person2(MyDate2 birthday, String name){
        this.birthday=birthday;
        this.name=name;
    }

    @Override
    public String toString() {
        return String.format("%s%s",name,birthday);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person2 p2=new Person2((MyDate2) birthday.clone(),name);
        return p2;
    }
}